window.onload=function()
{
    $.ajax({
        type:"GET",
        dataType: "json",
        contentType: "application/json",
        url:"/message/findAll",
        data: {

        },
        success:function(data){
            var wzy='';
            document.getElementById('tedit').innerHTML = "";
            for(var i=0;i<data.length;i++){
                var j=i+1;
                wzy += "<tr>" +"<td>" + "<input  type=\"radio\" name=\"personality\" id='" + data[i].id + "' >" + "</td>" + "<th>" + data[i].number+ "</th>"+"<th contentEditable='true'>" + data[i].failure+ "</th>" + "<th contentEditable='true'>" +data[i].grade+ "</th>" + "<td contentEditable='true'>" + data[i].success + "</td>" +"</tr>";
            }
            $("#tedit").append(wzy);
        },
        error: function () {
            alert("查询失败");
        }
    })
}

function getCookie(c_name)//获取cookie内容
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}
var username=getCookie('username');
if(username=='')
{
    setTimeout('location.href="login.html";',0);
}
function edit1()
{
    var nodes = document.getElementsByTagName("input");
    var biao=0;
    var s;
    for(var i=0;i<nodes.length;i++)
    {
        if(nodes[i].type=="radio" && nodes[i].checked) {
            s = parseInt(nodes[i].id);
            biao=1;
        }
    }
    if(biao==0)
    {
        alert('请勾选')
    }
    else {
        var mytable = document.getElementById('tableedit');
        for (var i = 1, rows = mytable.rows.length; i < rows; i++) {
            if (mytable.rows[i].cells[0].getElementsByTagName("INPUT")[0].id == s) {
                var  failure= mytable.rows[i].cells[2].innerHTML;
                var number=mytable.rows[i].cells[1].innerHTML;
                var grade = mytable.rows[i].cells[3].innerHTML;
                var success = mytable.rows[i].cells[4].innerHTML;
            }
        }
        var message =[
            {
                "failure": failure,
                "grade": grade,
                "id": s,
                "number": number,
                "success": success
            }
        ];
        $.ajax({
            type: "POST",
            dataType: "json",
            contentType: "application/json",
            url: "/message/updateMessages",
            data: JSON.stringify(message),
            success: function (data) {
                alert("修改成功");
                location.reload();
            },
            error: function () {
                alert("修改失败");
            }
        })
    }
}